// pages/vehicle/vehicle.js
const VEH = require("../../interfaces/vehicles")
const IFS = require("../../interfaces/interface")
Page({
  /**
   * 页面的初始数据
   */
  data: {
    vehicleNum: 0,
    vehicleArray: [
      {
        car_id: "12345",
        name: "bmw",
        power_capacity: 12,
        power_current: 6
      },
      {
        car_id: "11111",
        name: "benz",
        power_capacity: 13,
        power_current: 7
      }
    ],
    recentCarID: 0,
    isAdding: false,
    isEditing: false,
    cur_car_name: "",
    cur_car_curP: "",
    cur_car_capP: "",
    t_name: "",
    t_curP: "",
    t_capP: ""
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.setData({
      vehicleArray: VEH.getAllVehicles()
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   * 每次加载页面时都要更新车辆数据
   */
  onShow() {
    this.setData({
      vehicleArray: VEH.getAllVehicles()
    })
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {
    this.onShow()
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },
  onAdd(e)
  {
    wx.navigateTo({
      url: '/pages/vehicleEditor/vehicleEditor?action=add'
    })
  },
  /*edit键仅用于获取当前车辆信息，具体需要修改的值应该在onConfirm中判断*/
  onEdit(e) {
    this.setData({
      recentCarID: e.currentTarget.dataset.tid,
      cur_car_name: e.currentTarget.dataset.tname,
      cur_car_curP: e.currentTarget.dataset.tcurp,
      cur_car_capP: e.currentTarget.dataset.tcapp
    })
    wx.navigateTo({
      url: '/pages/vehicleEditor/vehicleEditor?action=edit'+'&id='+this.data.recentCarID+'&name='+this.data.cur_car_name+"&curp="+this.data.cur_car_curP+"&capp="+this.data.cur_car_capP
    })
  }

})